﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpComm;

namespace DAL.Enums
{
    #region 卡类型
    /// <summary>
    /// 卡类型
    /// </summary>
    public class UserRole : MyEnum<byte>
    {
        public static readonly UserRole All = new UserRole(0, "所有人员");
        public static readonly UserRole Maintain = new UserRole(1, "注册人员");
        public static readonly UserRole ByMonth = new UserRole(2, "按月会员");
        public static readonly UserRole ByTimes = new UserRole(3, "按量会员");
        public static readonly UserRole TryoutMonth = new UserRole(4, "按月试用");
        public static readonly UserRole TryoutTimes = new UserRole(5, "按量试用");
        public static readonly UserRole BlackList = new UserRole(8, "黑名单");

        /// <summary>
        /// 自动生成List
        /// </summary>
        private static List<UserRole> _Items;
        public static List<UserRole> Items
        {
            get
            {
                if (_Items == null)
                {
                    var _Type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
                    _Items =
                        _Type.GetFields().Where(field => field.FieldType == _Type).Select(
                            field => (UserRole)field.GetValue(null)).ToList();
                }
                return _Items;
            }
        }

        public static UserRole Get(byte type)
        {
            return Items.SingleOrDefault(p => p.Value == type);
        }

        public static UserRole Get(string descript)
        {
            return Items.SingleOrDefault(p => p.Text == descript);
        }

        //私有构造函数,有效阻止在类型外部生成实例
        private UserRole(byte value, string text)
        {
            _Value = value;
            _Text = text;
        }
    }
    #endregion
}
